home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.awt;
-
- import java.awt.AWTException;
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.Point;
- import symantec.beans.Beans;
- import symantec.itools.util.Timer;
-
- public abstract class ButtonBase extends Canvas {
- protected boolean pressed = false;
- protected boolean released = true;
- protected boolean inButton;
- protected boolean notifyWhilePressed = false;
- protected boolean showInfoTip = false;
- protected boolean running = false;
- protected boolean notified = false;
- protected boolean showFocus;
- protected boolean doInfoTip;
- protected int bevel;
- protected int notifyDelay;
- protected int infoTipDelay;
- protected int pressedAdjustment;
- protected String infoTipText;
- protected Color infoTipTextColor;
- protected Timer notifyTimer = null;
- protected Timer infoTipTimer = null;
- protected int infoTipX;
- protected int infoTipY;
- protected LayoutManager infoTipLayoutManager;
-
- protected ButtonBase() {
- this.infoTipTextColor = Color.black;
- this.notifyDelay = 1000;
- this.infoTipDelay = 1000;
- this.bevel = 1;
- this.pressedAdjustment = 0;
- ((Component)this).resize(10, 10);
- }
-
- public void setBevelHeight(int var1) {
- try {
- this.checkBevelSize(var1);
- } catch (AWTException var2) {
- System.err.println("Invalid Bevel Size " + var1);
- }
-
- this.bevel = var1;
- ((Component)this).invalidate();
- }
-
- public int getBevelHeight() {
- return this.bevel;
- }
-
- public void setNotifyWhilePressed(boolean var1) {
- this.notifyWhilePressed = var1;
- if (this.notifyWhilePressed) {
- this.notifyTimer = new Timer(this, this.notifyDelay, true, 1001);
- } else {
- if (this.notifyTimer != null) {
- this.notifyTimer = null;
- }
-
- }
- }
-
- public boolean getNotifyWhilePressed() {
- return this.notifyWhilePressed;
- }
-
- public void setNotifyDelay(int var1) {
- this.notifyDelay = var1;
- }
-
- public int getNotifyDelay() {
- return this.notifyDelay;
- }
-
- public void setShowInfoTip(boolean var1) {
- this.showInfoTip = var1;
- if (this.showInfoTip) {
- this.infoTipTimer = new Timer(this, this.notifyDelay, true, 1001);
- } else {
- if (this.infoTipTimer != null) {
- this.infoTipTimer = null;
- }
-
- }
- }
-
- public boolean getShowInfoTip() {
- return this.showInfoTip;
- }
-
- public void setInfoTipDelay(int var1) {
- this.infoTipDelay = var1;
- }
-
- public int getInfoTipDelay() {
- return this.infoTipDelay;
- }
-
- public void setShowFocus(boolean var1) {
- this.showFocus = var1;
- }
-
- public boolean getShowFocus() {
- return this.showFocus;
- }
-
- public void setInfoTipText(String var1) {
- this.infoTipText = var1;
- }
-
- public String getInfoTipText() {
- return this.infoTipText;
- }
-
- public void setInfoTipTextColor(Color var1) {
- this.infoTipTextColor = var1;
- }
-
- public Color getInfoTipTextColor() {
- return this.infoTipTextColor;
- }
-
- public boolean mouseUp(Event var1, int var2, int var3) {
- if (this.running) {
- this.running = false;
- this.notifyTimer.stop();
- }
-
- if (this.pressed) {
- this.pressed = false;
- this.pressedAdjustment = 0;
- if (!this.notifyWhilePressed || !this.notified) {
- ((Component)this).postEvent(new Event(this, 1001, (Object)null));
- }
- }
-
- this.released = true;
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- if (this.notifyWhilePressed && !this.running) {
- this.running = true;
- this.notifyTimer.start();
- }
-
- this.pressed = true;
- this.released = false;
- this.pressedAdjustment = this.bevel;
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseEnter(Event var1, int var2, int var3) {
- this.inButton = true;
- if (this.showInfoTip) {
- this.infoTipX = var2;
- this.infoTipY = var3;
- this.infoTipTimer.start();
- }
-
- if (!this.released) {
- this.mouseDown(var1, var2, var3);
- }
-
- return true;
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- this.inButton = false;
- if (this.showInfoTip) {
- this.infoTipTimer.stop();
- Panel var4 = InfoTipManager.getInfoTipPanel();
- ((Component)var4).getParent().setLayout(this.infoTipLayoutManager);
- ((Component)var4).hide();
- }
-
- if (this.pressed) {
- this.pressed = false;
- this.pressedAdjustment = 0;
- }
-
- return true;
- }
-
- public boolean action(Event var1, Object var2) {
- if (this.notifyWhilePressed && var1.target == this.notifyTimer && !Beans.isDesignTime()) {
- ((Component)this).postEvent(new Event(this, 1001, (Object)null));
- return true;
- } else if (this.showInfoTip && var1.target == this.infoTipTimer) {
- this.doInfoTip = true;
- ((Component)this).repaint();
- this.infoTipTimer.stop();
- return true;
- } else {
- return super.action(var1, var2);
- }
- }
-
- public void enable() {
- if (!((Component)this).isEnabled()) {
- super.enable();
- this.pressed = false;
- this.pressedAdjustment = 0;
- }
-
- ((Component)this).repaint();
- }
-
- public void disable() {
- if (((Component)this).isEnabled()) {
- super.disable();
- if (this.notifyTimer != null) {
- this.notifyTimer.stop();
- }
-
- if (this.infoTipTimer != null) {
- this.infoTipTimer.stop();
- }
-
- this.pressed = false;
- this.pressedAdjustment = 0;
- }
-
- ((Component)this).repaint();
- }
-
- public void update(Graphics var1) {
- Dimension var2 = ((Component)this).size();
- var1.clipRect(0, 0, var2.width, var2.height);
- this.paint(var1);
- }
-
- public void paint(Graphics var1) {
- Dimension var2 = ((Component)this).size();
- int var3 = var2.width;
- int var4 = var2.height;
- int var5 = this.bevel + 1;
- int var6 = this.bevel + 1;
- int var7 = var3 - 1;
- int var8 = var4 - 1;
- var1.setColor(Color.lightGray);
- var1.fillRect(0, 0, var3, var4);
- if (this.pressed) {
- int var10000 = var5 + (this.bevel > 0 ? 2 : 1);
- var1.setColor(Color.lightGray);
-
- for(int var9 = 1; var9 < this.bevel + 1; ++var9) {
- var1.drawLine(var9, var8 - var9, var7 - var9, var8 - var9);
- var1.drawLine(var7 - var9, var8 - var9, var7 - var9, var9);
- }
-
- var1.setColor(Color.gray);
-
- for(int var10 = 1; var10 < this.bevel + 1; ++var10) {
- var1.drawLine(var10, var8, var10, var10);
- var1.drawLine(var10, var10, var7, var10);
- }
- } else {
- var1.setColor(Color.white);
-
- for(int var11 = 1; var11 < this.bevel + 1; ++var11) {
- var1.drawLine(var11, var8 - var11, var11, var11);
- var1.drawLine(var11, var11, var7 - var11, var11);
- }
-
- var1.setColor(Color.gray);
-
- for(int var12 = 1; var12 < this.bevel + 2; ++var12) {
- var1.drawLine(var12, var8 - var12, var7 - var12, var8 - var12);
- var1.drawLine(var7 - var12, var8 - var12, var7 - var12, var12);
- }
- }
-
- var1.setColor(Color.black);
- var1.drawLine(1, 0, var3 - 2, 0);
- var1.drawLine(0, 1, 0, var4 - 2);
- var1.drawLine(1, var4 - 1, var3 - 2, var4 - 1);
- var1.drawLine(var3 - 1, var4 - 2, var3 - 1, 1);
- if (this.showInfoTip && this.doInfoTip) {
- this.drawInfoTip();
- }
-
- }
-
- protected void drawInfoTip() {
- this.doInfoTip = false;
- Point var2 = ((Component)this).location();
- Panel var1 = InfoTipManager.getInfoTipPanel();
- this.infoTipX += var2.x;
- this.infoTipY += var2.y;
- this.infoTipLayoutManager = ((Component)var1).getParent().getLayout();
- InfoTipManager.draw(this.infoTipX, this.infoTipY, this.infoTipText, ((Component)this).getFontMetrics(((Component)this).getFont()), Color.yellow, Color.black);
- }
-
- private void checkBevelSize(int var1) throws AWTException {
- Dimension var2 = ((Component)this).size();
- if (var1 < 0 || var1 >= var2.width / 2 || var1 >= var2.height / 2) {
- throw new AWTException("invalid bevel size");
- }
- }
- }
-